package com.example.medical.controller.admin;

import com.example.medical.entity.dto.GetListDto;
import com.example.medical.entity.pojo.DeviceType;
import com.example.medical.entity.pojo.NoticeType;
import com.example.medical.service.NoticeTypeService;
import com.example.medical.utils.common.enums.Code;
import com.example.medical.utils.common.result.Result;
import com.example.medical.utils.config.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/notice_type")
public class AdminNoticeTypeController {

    @Autowired
    private NoticeTypeService noticeTypeService;

    @PostMapping("/get_notice_type_list")
    public Result AdminGetNoticeTypeList(@RequestBody GetListDto dto){
        return noticeTypeService.AdminGetNoticeTypeList(dto);
    }

    @GetMapping("/get_notice_type_detail")
    public Result AdminGetNoticeDetail(@RequestParam("id")Long id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        return Result.okResult(noticeTypeService.getById(id));
    }

    @PostMapping("/save_notice_type")
    public Result AdminSaveNoticeType(@RequestParam("name")String name){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        NoticeType noticeType=new NoticeType();
        noticeType.setNoticeTypeName(name);
        noticeTypeService.save(noticeType);
        return Result.okResult(Code.SUCCESS);
    }

    @GetMapping("/remove_notice_type")
    public Result AdminRemoveNoticeType(@RequestParam("id")Long id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        boolean checkRemove = noticeTypeService.removeById(id);
        if (!checkRemove) {
            return Result.errorResult(Code.SERVER_ERROR);
        }
        return Result.okResult(Code.SUCCESS);
    }

    @GetMapping("/remove_notice_type_arr")
    public Result AdminRemoveNoticeTypeArr(@RequestParam("ids")String[] ids){
        return noticeTypeService.AdminRemoveNoticeTypeArr(ids);
    }

    @GetMapping("/update_get_notice_type")
    public Result AdminUpdateGetNotice(@RequestParam("id")Long id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        return Result.okResult(noticeTypeService.getById(id));
    }

    @PostMapping("/update_notice_type")
    public Result AdminUpdateNoticeType(@RequestParam("id")Long id,
                                        @RequestParam("name")String name){
        return noticeTypeService.AdminUpdateNoticeType(id,name);
    }

}
